use diesel::prelude::*;
use chrono::{DateTime, Utc};

#[derive(Queryable, Selectable, Insertable)]
#[diesel(table_name = crate::schema::posts)]
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
pub struct Post {
    pub id: i32,
    pub title: String,
    pub body: String,
    pub published: bool,
}

#[derive(Insertable)]
#[diesel(table_name = crate::schema::posts)]
pub struct NewPost<'a> {
    pub title: &'a str,
    pub body: &'a str,
}

#[derive(Queryable, Selectable, Insertable)]
#[diesel(table_name = crate::schema::executor_status)]
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
pub struct ExecutorStatus {
    pub id: i32,
    pub task_type: String,
    pub task_data: String,
    pub status: String,
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
}

#[derive(Queryable, Selectable, Insertable)]
#[diesel(table_name = crate::schema::spider_task)]
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
pub struct SpiderTask {
    pub id: String,
    pub task_schema: String,
}

#[derive(Queryable, Selectable, Insertable)]
#[diesel(table_name = crate::schema::spider_task_status)]
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
pub struct SpiderTaskStatus {
    pub id: String,
    pub task_id: String,
    pub task_data: String,
    pub status: String,
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>
}